package com.xx.sg.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.xx.sg.own.entity.WatchTower;
import com.xx.sg.own.service.WatchTowerService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/watchTower")
@Tag(name = "瞭望塔数据", description = "瞭望塔数据API")
public class WatchTowerController {

    @Autowired
    private WatchTowerService watchTowerService;

    @PostMapping("/add")
    @Operation(summary = "批量新增", description = "批量新增")
    public void add(@RequestBody List<WatchTower> list) {
        watchTowerService.saveBatch(list);
    }

    @GetMapping("/info/{areaId}")
    public Map info(@PathVariable("areaId") String areaId) {
        LambdaQueryWrapper<WatchTower> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(WatchTower::getAreaId, areaId);
        WatchTower watchTower = watchTowerService.getOne(wrapper);
        Map<String, Object> res = new HashMap<>();
        res.put("success", true);
        res.put("code", 200);
        res.put("message", "成功");
        res.put("data", watchTower);
        return res;
    }


}
